home *** CD-ROM | disk | FTP | other *** search
/ Utilities Professional 1-1500 / Utilities Professional 1-1500 (1994)(WPD)[!].iso / 12511500 / var1458.dms / var1458.adf / IDCMP / Example3.c < prev    next >
C/C++ Source or Header  |  1992-05-01  |  6KB  |  176 lines

  1. /***********************************************************/
  2. /*                                                         */
  3. /* Amiga C Encyclopedia (ACE) V3.0      Amiga C Club (ACC) */
  4. /* -------------------------------      ------------------ */
  5. /*                                                         */
  6. /* Book:    ACM Intuition               Amiga C Club       */
  7. /* Chapter: IDCMP                       Tulevagen 22       */
  8. /* File:    Example3.c                  181 41  LIDINGO    */
  9. /* Author:  Anders Bjerin               SWEDEN             */
  10. /* Date:    92-05-01                                       */
  11. /* Version: 1.10                                           */
  12. /*                                                         */
  13. /*   Copyright 1992, Anders Bjerin - Amiga C Club (ACC)    */
  14. /*                                                         */
  15. /* Registered members may use this program freely in their */
  16. /*     own commercial/noncommercial programs/articles.     */
  17. /*                                                         */
  18. /***********************************************************/
  19.  
  20. /* This program explains how to use the IDCMP flags: NEWSIZE, */
  21. /* ACTIVEWINDOW and INACTIVEWINDOW.                           */
  22.  
  23.  
  24.  
  25. #include <intuition/intuition.h>
  26.  
  27.  
  28.  
  29. struct IntuitionBase *IntuitionBase;
  30.  
  31.  
  32.  
  33. /* Declare a pointer to a Window structure: */ 
  34. struct Window *my_window;
  35.  
  36. /* Declare and initialize your NewWindow structure: */
  37. struct NewWindow my_new_window=
  38. {
  39.   50,             /* LeftEdge    x position of the window. */
  40.   25,             /* TopEdge     y positio of the window. */
  41.   320,            /* Width       320 pixels wide. */
  42.   100,            /* Height      100 lines high. */
  43.   0,              /* DetailPen   Text should be drawn with colour reg. 0 */
  44.   1,              /* BlockPen    Blocks should be drawn with colour r. 1 */
  45.   CLOSEWINDOW|    /* IDCMPFlags  We will recieve a message when the user: */
  46.                   /*             selects the Close window gad, or when    */
  47.  
  48.   NEWSIZE|        /*             the user resizes the window.             */
  49.   ACTIVEWINDOW|   /*             We will also recieve a message whenever  */
  50.   INACTIVEWINDOW, /*             the window is activated/deactivated.     */
  51.  
  52.   SMART_REFRESH|  /* Flags       Intuition should refresh the window. */
  53.   WINDOWCLOSE|    /*             Close Gadget. */
  54.   WINDOWDRAG|     /*             Drag gadget. */
  55.   WINDOWDEPTH|    /*             Depth arrange Gadgets. */
  56.   WINDOWSIZING|   /*             Sizing Gadget. */
  57.   ACTIVATE,       /*             The window should be Active when opened. */
  58.   NULL,           /* FirstGadget No gadgets connected to this window. */
  59.   NULL,           /* CheckMark   Use Intuition's default CheckMark. */
  60.   "PLAY WITH WINDOWS", /* Title  Title of the window. */
  61.   NULL,           /* Screen      Connected to the Workbench Screen. */
  62.   NULL,           /* BitMap      No Custom BitMap. */
  63.   100,            /* MinWidth    We will not allow the window to become */
  64.   50,             /* MinHeight   smaller than 100 x 50, and not bigger */
  65.   400,            /* MaxWidth    than 400 x 200. */
  66.   200,            /* MaxHeight */
  67.   WBENCHSCREEN    /* Type        Connected to the Workbench Screen. */
  68. };
  69.  
  70.  
  71.  
  72. main()
  73. {
  74.   /* Boolean variable used for the while loop: */
  75.   BOOL close_me;
  76.  
  77.   ULONG class; /* IDCMP flag. */
  78.  
  79.   /* Pointer to an IntuiMessage structure: */
  80.   struct IntuiMessage *my_message;
  81.  
  82.  
  83.  
  84.   /* Before we can use Intuition we need to open the Intuition Library: */
  85.   IntuitionBase = (struct IntuitionBase *)
  86.     OpenLibrary( "intuition.library", 0 );
  87.   
  88.   if( IntuitionBase == NULL )
  89.     exit(); /* Could NOT open the Intuition Library! */
  90.  
  91.  
  92.  
  93.   /* We will now try to open the window: */
  94.   my_window = (struct Window *) OpenWindow( &my_new_window );
  95.   
  96.   /* Have we opened the window succesfully? */
  97.   if(my_window == NULL)
  98.   {
  99.     /* Could NOT open the Window! */
  100.     
  101.     /* Close the Intuition Library since we have opened it: */
  102.     CloseLibrary( IntuitionBase );
  103.  
  104.     exit();  
  105.   }
  106.  
  107.  
  108.  
  109.   /* We have opened the window, and everything seems to be OK. */
  110.  
  111.   printf("Play with the window!\n\n");
  112.  
  113.  
  114.  
  115.   close_me = FALSE;
  116.  
  117.   /* Stay in the while loop until the user has selected the Close window */
  118.   /* gadget: */
  119.   while( close_me == FALSE )
  120.   {
  121.     /* Wait until we have recieved a message: */
  122.     Wait( 1 << my_window->UserPort->mp_SigBit );
  123.  
  124.  
  125.     /* As long as we can collect messages successfully we stay in the */
  126.     /* while-loop: */
  127.     while(my_message = (struct IntuiMessage *) GetMsg(my_window->UserPort))
  128.     {
  129.       /* After we have successfully collected the message we can read */
  130.       /* it, and save any important values which we maybe want to check */
  131.       /* later: */
  132.       class = my_message->Class;  /* IDCMP flag. */
  133.  
  134.  
  135.       /* After we have read it we reply as fast as possible: */
  136.       /* REMEMBER! Do never try to read a message after you have replied! */
  137.       /* (Some other process has maybe changed it.) */
  138.       ReplyMsg( my_message );
  139.  
  140.  
  141.       /* Check which IDCMP flag was sent: */
  142.       switch( class )
  143.       {
  144.         case CLOSEWINDOW:    /* The user selected the Close window gad. */
  145.                close_me=TRUE;
  146.                break;
  147.         
  148.         case NEWSIZE:        /* The user resized the window. */
  149.                printf("The window was resized!\n");
  150.                printf("Width: %d\n", my_window->Width);
  151.                printf("Height: %d\n\n", my_window->Height);
  152.                break;
  153.  
  154.         case ACTIVEWINDOW:   /* Window actiavted. */
  155.                printf("Window activated!\n\n");
  156.                break;
  157.  
  158.         case INACTIVEWINDOW: /* Window inactiavted. */
  159.                printf("Window inactivated!\n\n");
  160.                break;
  161.       }
  162.     }
  163.   }
  164.  
  165.  
  166.  
  167.   /* Close the window: */
  168.   CloseWindow( my_window );
  169.  
  170.  
  171.  
  172.   /* Close the Intuition Library: */
  173.   CloseLibrary( IntuitionBase );
  174.   
  175.   /* THE END */
  176. }